<template>
  <a-tree-select
    v-model="myValue"
    :tree-data="treeData"
    :show-search="true"
    :style="`width: ${width}`"
    :dropdown-style="{
      maxHeight: '400px',
      overflow: 'auto'
    }"
    :placeholder="placeholder"
    searchPlaceholder="输入关键字搜索"
    @change="change"
    :allowClear="isClear"
    :disabled="disabled"
  >
  </a-tree-select>
</template>
<script>
import { DATA_BASE_SFAPPROVE } from '@/store/mutation-types.js'
export default {
  props: {
    field: {
      type: String,
      require: true
    },
    index: {
      type: Number
    },
    width: {
      type: String,
      default: '70%'
    },
    placeholder: {
      type: String,
      default: '请选择数据表'
    },
    // 数据源
    database: {
      type: String,
      default: DATA_BASE_SFAPPROVE
    },
    // 回显值
    value: {
      type: String
    },
    // 是否支持清除
    isClear: {
      type: Boolean,
      default: true
    },
    // 是否禁用
    disabled: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      myValue: this.value || undefined,
      treeData:
        this.database == DATA_BASE_SFAPPROVE
          ? this.$store.state.tables.tableList
          : []
    }
  },
  created() {},
  watch: {
    value(val) {
      this.myValue = val
    },
    f_treeData(val) {
      this.treeData = val
    }
  },
  methods: {
    // 树下拉回显
    change(value) {
      this.$emit('f_setTable', value, this.field, this.index)
    }
  }
}
</script>

<style lang="less" scoped></style>
